package com.study.thread.locksupport;

/**
 * @Author zh wang
 * @Create 2024/12/16 16:57
 */
import java.util.concurrent.locks.LockSupport;

public class LockSupportDemo {
    public static void main(String[] args) throws InterruptedException {
        Thread thread=new Thread(()->{
            System.out.println("child thread begin park");
            LockSupport.park();
            // 使用 while 循环持续检查中断状态
            //while (Thread.currentThread().isInterrupted()) {
            //    System.out.println("thread is interrupted");
            //    return;
            //}
            System.out.println("child thread unpark");
        });
        thread.start();

        Thread.sleep(1000);//主线程休眠1s
        //LockSupport.unpark(thread);//调用 unpark方法让 thread线程持有许可证，然后park方法返回
        thread.interrupt();
    }
}
